<?php
/**
 * Created by PhpStorm.
 * User: 12133
 * Date: 2024/1/17
 * Time: 17:22
 */

namespace app\controller\index;



use app\model\index\Config;
use think\facade\Cookie;

class Index extends Base
{
    public function config(){
        $config = \app\model\Config::select();
        $system = [];
        foreach ($config AS $key => $value){
            $system[$value['key']] = $value['value'];
        }
        return $this->msg($system);
    }

    public function index(){
        $mk = input('mk',0);
        $keyword = input('keyword');
        $free_frequency = Config::get_value('free_frequency');
        $array = [];
        if (Cookie::has('keywords_list'))
            $array = json_decode(Cookie::get('keywords_list'),true);
        $user = \app\model\index\User::where('username',$_SESSION['username'])->find();
        $rule = json_decode($user->rule,true);
        $rule = empty($rule) ? [] : $rule;
        return $this->view(
            '/index/index',[
                'mk' => $mk,
                'number' => $free_frequency,
                'keywords' => $array,
                'user' => $user,
                'keyword' => $keyword,
                'is_message' => in_array('message',$rule) ? 1 : 0,
                'is_order' => in_array('order',$rule)
        ]);
    }

    public function test(){
        $keyword = input('keyword');
        $free_frequency = Config::get_value('free_frequency');
        $array = [];
        if (Cookie::has('keywords_list'))
            $array = json_decode(Cookie::get('keywords_list'),true);
        $user = \app\model\index\User::where('username',$_SESSION['username'])->find();
        return $this->view('/index/test',['number' => $free_frequency,'keywords' => $array,'user' => $user,'keyword' => $keyword]);
    }

    public function product(){
        return $this->view('/index/product/list');
    }
}